<template>
	<view class="x-wrapper">
		<view class="x-main-content">
			<view class="hosp-box">
				<u-navbar :title="title" :fixed="true" leftIcon="arrow-left" leftIconColor="#000" leftIconSize="42rpx"
					autoBack placeholder>
				</u-navbar>
				<view style="position: fixed;width: 100%;z-index: 9;height: 50rpx;right: 0;">
					<search></search>
				</view>
				<view class="list-box">
					<template v-if="hospitalList&&hospitalList.length">
						<hosp-item v-for="(item, index) in hospitalList" :key="item.id" :item="item"></hosp-item>
					</template>
					<!-- <template v-if="hospitalList.length">
						<hosp-item v-for="(item, index) in hospitalList" :key="item.id" :item="item"></hosp-item>
						<view class="lists" style="display: flex;" v-for="(item, index) in hospitalList" :key="item.id"
							 @click="goDetail()">
							<view class="img-box">
								<u--image :src="item.image" width="97rpx" height="97rpx" radius="18rpx 0px 0px 18rpx">
								</u--image>
							</view>
							<view class="r-content">
								<view class="name ellipses-one">{{item.name}}</view>
								<view class="labels ellipses-one">
									<text class="label">{{item.level}}</text><text class="label">{{item.nature}}</text>
								</view>
							</view>
							
						</view>
					</template> -->
					<view class="x-no-data" v-if="hospitalList.length===0">
						<u-empty text="暂无数据" mode="data" marginTop="100"></u-empty>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import search from '@/components/search.vue'
	import hospItem from '@/components/list/index'
	import hospitalCard from "../../pages/business/components/hospitalCard.vue"
	export default {
		components: {
			hospitalCard,
			hospItem,
			search
		},
		data() {
			return {
				params: {
					cityCode: '',
					pageNum: 1,
					pageSize: 10
				},
				hospitalList: [],
				listTotal: '',
				title: "",
			}
		},

		onLoad(e) {
			let filteredObjects = JSON.parse(decodeURIComponent(e.data))
			this.hospitalList = filteredObjects
			this.hospitalList.forEach((item)=>{
				// console.log(item.type)
				if(item.type=='1'){
					this.title="就医陪诊"
				}else if(item.type=='2'){
					this.title="夜间陪诊"
				}else{
					this.title="VIP陪诊"
				}
			})
		},
		// onShow() {
		// 	// uni.showLoading({
		// 	// 	title: '加载中',
		// 	// 	mask: true
		// 	// })
		// 	this.getHospitalData()
		// },
		computed: {
			totalPage() {
				return Math.ceil(this.listTotal / this.params.pageSize)
			}
		},
		onReachBottom() {
			this.params.pageNum++
			if (this.params.pageNum > this.totalPage) {
				return
			} else {
				this.getHospitalData()
			}
		},
		methods: {
			goDetail(item){
				uni.navigateTo({
					url: '/pages/business/chaperonage?data=' + encodeURIComponent(JSON.stringify(item))
				})
			},
			async getHospitalData() {
				this.params.cityCode = uni.getStorageSync('myAddress').cityId
				console.log(uni.getStorageSync('myAddress'))
				let res = await this.$request('/api/index/getAllHospitalList', this.params, 'GET')
				console.log(res)
				if (res.data.rows.length) {
					for (let i = 0; i < res.data.rows.length; i++) {
						this.hospitalList.push(res.data.rows[i])
					}
					this.listTotal = res.data.total
					// uni.hideLoading()
				}
			}
			// async getHospitalData() {
			// 	this.params.cityCode = uni.getStorageSync('myAddress').cityId
			// 	// console.log(uni.getStorageSync('myAddress'))
			// 	let res = await this.$request('/api/index/getAllHospitalList', this.params, 'GET')
			// 	// console.log(res)
			// 	if (res.data.rows.length) {
			// 		for (let i = 0; i < res.data.rows.length; i++) {
			// 			this.hospitalList.push(res.data.rows[i])
			// 		}
			// 		// this.listTotal = res.data.total
			// 		// uni.hideLoading()
			// 	}
			// }
		}
	}
</script>

<style lang="scss" scoped>
	.hosp-box {
		.top-box {
			padding: 20rpx 40rpx 30rpx;
			background: #fff;

			.search-box {
				height: 64rpx;
				background: #F8FAFF;
				border-radius: 64rpx;
				display: flex;
				align-items: center;
				// margin-bottom: 24rpx;

				.s-btn {
					margin-right: 5rpx;
					width: 118rpx;
					height: 54rpx;

					/deep/ .u-button__text {
						font-size: 24rpx !important;
					}
				}
			}
		}
	}

	.list-box {
		padding: 0 40rpx 1rpx;
		margin-top: 120rpx;


		.lists{
			height: 48px;
			margin: 20rpx 0;
			background-color: #FFF;
			
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			.r-content{
				display: flex;
				align-items: center;
				.name{
					margin-left: 20rpx;
				}
			}
			.r1-content{
				display: flex;
				align-items: flex-end;
				justify-content: space-between;
				font-size: 25rpx;
				width: 50%;
			
			}

		}

		// .hosp-item {
		// 	&:last-child {
		// 		margin-bottom: 0;
		// 	}
		// }
	}
</style>